package com.bai.ad.util;

import com.bao.ad.exception.AdException;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.time.DateUtils;

import java.util.Date;

/**
 * ClassName CommonUtils
 *
 * @author Bai
 * @version 1.0
 * @date 2019/2/19 0019 下午 22:16
 **/
public class CommonUtils {

    private static String[] parsePatterns = {
            "yyyy-MM-dd", "yyy/MM/dd", "yyy.MM.dd"
    };

    public static String md5(String value){
        return DigestUtils.md5Hex(value).toUpperCase();
    }

    public static Date parseStringDate(String dateString) throws AdException{
        try {
            return DateUtils.parseDate(dateString, parsePatterns);
        }catch (Exception e){
            throw new AdException(e.getMessage());
        }
    }
}
